﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace easy_app
{
    class Presenter
    {
        public List<User> _userList { get; set; }
        private IView _view;
        private int counter = -1;

        public Presenter(IView view)
        {
            _userList = new List<User>();
            _userList.Add(new User("Vasya", "Pupkin"));
            _userList.Add(new User("Olga", "Popka"));
            _userList.Add(new User("Sveta", "Siska"));            
            _view = view;
            _view.nextButtonPressed += new EventHandler<EventArgs>(OnNextButtonPressed);
            _view.previousButtonPressed += new EventHandler<EventArgs>(OnPreviousButtonPressed);
            _view.saveButtonPressed += new EventHandler<EventArgs>(OnSaveButtonPressed);

        }   

        private void OnNextButtonPressed(object sender, EventArgs e)
        {
            if (counter == _userList.Count - 1) return;
            else counter++;
            _view.SetName(_userList[counter].Name);
            _view.SetSurName(_userList[counter].SurName);
                                 
        }

        private void OnPreviousButtonPressed(object sender, EventArgs e)
        {
            if (counter == 0 || counter==-1) return;
            else counter--;
            _view.SetName(_userList[counter].Name);
            _view.SetSurName(_userList[counter].SurName);
           
        }

        private void OnSaveButtonPressed(object sender, EventArgs e)
        {
            _userList[counter].Name = _view.GetName();
            _userList[counter].SurName = _view.GetSurName();

        }
    }
}
